const Sequelize = require('sequelize')
const {sequelize} = require('./utils')

const Op = Sequelize.Op

// 创建用户实体
const UserProject = sequelize.define('user_project', {
        id: {
            type: Sequelize.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        user_id: {
            type: Sequelize.STRING,
            allowNull: false
        },
        project_id: {
            type: Sequelize.STRING,
            allowNull: false
        },
        is_admin: {
            type: Sequelize.BOOLEAN,
            defaultValue: false
        }
    }
);
UserProject.sync({force: false})
// /**插入新项目类型数据（添加） */
UserProject.insertData = async (user_id, project_id, is_admin) => {
    await UserProject.sync({force: false})
    // 表已创建
    return UserProject.create({user_id, project_id, is_admin})
}

 // 查找项目Id查找用户
UserProject.findByProjectId = async (project_id) => {
    return UserProject.findAll({where:{project_id} })
}
 // 查找用户Id查找用户
UserProject.findByUserId = async (user_id) => {
    return UserProject.findAll({where:{user_id} })
}
/** 删除项目成员 */
UserProject.removeUser = async (id) => {
    return UserProject.destroy({where: {id}})
}
export {UserProject}

